package com.carl.mall.third.utils;

import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.teautil.models.RuntimeOptions;
import com.carl.common.utils.R;
import lombok.Data;
import org.springframework.stereotype.Component;

@Component
@Data
public class Sample_reg {

    /**
     * 使用AK&SK初始化账号Client
     *
     * @return Client
     * @throws Exception
     */
    public  static com.aliyun.dysmsapi20170525.Client createClient() throws Exception {
        Config config = new Config()
                // 您的AccessKey ID
                .setAccessKeyId("LTAI5tNKHhjdq7u4NwMvvRec")
                .setAccessKeySecret("FTm8hygBceUWgbWkSycLbNWSpA1wPh");
                // 您的AccessKey Secret;
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        return new com.aliyun.dysmsapi20170525.Client(config);
    }

    public void sendSms(String phone, String code)  {
        try {
            com.aliyun.dysmsapi20170525.Client client = Sample_reg.createClient();
            SendSmsRequest sendSmsRequest = new SendSmsRequest()
                    //签名
                    .setSignName("SuperMall")
                    //模板
                    .setTemplateCode("SMS_471400348")
                    .setPhoneNumbers(phone)
                    //验证码
                    .setTemplateParam("{code:+" + code + "}");
            RuntimeOptions runtime = new RuntimeOptions();
            // 复制代码运行请自行打印 API 的返回值
            client.sendSmsWithOptions(sendSmsRequest, runtime);
        } catch (Exception e) {
           e.printStackTrace();
        }
    }

//    public static void main(String[] args) {
//        sendSms("15529330605","1234");
//    }


}